package chapter1.No1_7_停止线程.d在沉睡中停止;

/**
 * *：这个实验是先interrupt()中断再遇见sleep()。还是会出现异常
 *    总结：不管是先sleep还是先interrupt()都会报异常
 */
public class T1_MyThreadSleep extends Thread {

    @Override
    public void run() {
        try {
            for (int i = 0; i < 50000; i++) {
                System.out.println("i=" + i);
            }
            System.out.println("run begin");
            this.sleep(3000);
            System.out.println("run end");
        } catch (InterruptedException e) {
            System.out.println("先停止，再遇见sleep！进入catch");
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        T1_MyThreadSleep m1 = new T1_MyThreadSleep();
        m1.start();
        m1.interrupt();
        System.out.println("END");
    }
}
